//
//  QLMainViewController.swift
//  WeiBo01
//
//  Created by 黄跃奇 on 16/9/21.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit
                                                //MARK: - 5.(代理)遵守协议
class QLMainViewController: UITabBarController, QLTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        //使用kvc方式给oc中的类设置只读属性的值
        let qlTabBar = QLTabBar()
        setValue(qlTabBar, forKey: "tabBar")
        
        //MARK: - 4.(代理)设置代理
        qlTabBar.qlDelegate = self
        
        //MARK: - 3.(闭包)设置撰写按钮的闭包
        qlTabBar.composeButtonClosure = {
            
            print("我是闭包调用过来的")
            
        }
        
        //添加子视图控制器
        addChildViewController(childController: QLHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(childController: QLMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: QLDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: QLProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
    }
    
    //添加子视图控制器
    func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        //设置title
//        childController.tabBarItem.title = title
//        childController.navigationItem.title = title
        childController.title = title
        //设置图片及渲染方式
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        //设置文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 13)], for: .normal)
        //设置选中的文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        let nav = QLNavigationViewController(rootViewController: childController)
        addChildViewController(nav)
        
    }
    
    //MARK: - 6.(代理)实现代理方法
    func clickFinishedComposeButton() {
        
        print("我是代理对象调用过来的")
        
    }

}
